package com.yycx.module.bus.provider.handler.settle;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.interceptor.DeleteInterceptor;
import com.yycx.common.mybatis.query.CriteriaDelete;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.BusOrderDetailsService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * 结算删除扩展
 *
 * @author zyf
 */
@Component("settlePaymentDeleteHandler")
public class SettlePaymentDeleteHandler implements DeleteInterceptor {


    @Autowired
    private BusPaymentService paymentService;

    @Autowired
    private BusOrderDetailsService orderDetailsService;


    @Override
    public void prepare(CriteriaDelete cd, EntityMap entityMap) {
        Serializable paymentId = cd.getIdValue();
        BusPayment payment = paymentService.getById(paymentId);
        entityMap.put("settleType",payment.getSettleType());

    }

    @Override
    public void complete(CriteriaDelete cd, EntityMap params) {
        Serializable paymentId = cd.getIdValue();
        Integer settleType=params.getInt("settleType",1);
        orderDetailsService.clearJiesuanInfo(paymentId,settleType);
    }
}
